const connections = require('../app/database');

class SystemService {
    // 获取用户菜单id
    async getMenuListById(userId) {
        const statement = `SELECT * FROM role where id = ?`;
        const result = await connections.execute(statement, [userId]);
        return result[0];
    }

    //获取全部角色菜单列表
    async getMenuList() {
        const statement = `SELECT * FROM role_menu`;
        const result = await connections.execute(statement);
        return result[0];
    }

    // 获取全部角色权限列表
    async getRoleList() {
        const statement = `SELECT * FROM role`;
        const result = await connections.execute(statement);
        return result[0];
    }

    // 添加权限
    async addRole(menuId, name) {
        const statement = `INSERT INTO role (menuId, name) VALUES (?, ?);`;
        const result = await connections.execute(statement, [menuId, name]);
        return result;
    }

    // 删除权限
    async deleteRole(roleId) {
        const statement = `DELETE FROM role WHERE id = ?;`;
        const result = await connections.execute(statement, [roleId]);
        return result;
    }
}

module.exports = new SystemService();